package com.yzqp.blog.interceptor;


import org.springframework.web.bind.annotation.ControllerAdvice;

@ControllerAdvice
public class ExceptionHandle {

//    @Autowired
//    LogService logService;
//
//    @ExceptionHandler(value = Exception.class)
//    @ResponseBody
//    public WebJsonResult<?> handler(Exception e) {
//        // 操作异常
//        if (e instanceof GlobalRuntimeException) {
//            HttpServletRequest request = YzqpUtils.getServletRequest();
//            log(LogTypeEnum.BUSINESS_ERROR, e);
//            LogUtil.getBean().error("----start----------------------------------------------------------------------------------------");
//            LogUtil.getBean().info("URL : " + request.getRequestURL().toString());
//            LogUtil.getBean().info("HTTP_METHOD : " + request.getMethod());
//            LogUtil.getBean().info("IP : " + request.getRemoteAddr());
//            LogUtil.getBean().error("[操作异常]:{}", e.getMessage());
//            LogUtil.getBean().error("-----end---------------------------------------------------------------------------------------");
//            if(((GlobalRuntimeException) e).getState() == WebJsonResultUtil.LOGIN_ERR){
//                return WebJsonResultUtil.errorLogin("登录异常或者token过期");
//            }
//            return WebJsonResultUtil.error(e.getMessage());
//        }
//        // 系统异常
//        HttpServletRequest request = YzqpUtils.getServletRequest();
//        log(LogTypeEnum.SYS_ERROR, e);
//        LogUtil.getBean().error("----start----------------------------------------------------------------------------------------");
//        LogUtil.getBean().info("URL : " + request.getRequestURL().toString());
//        LogUtil.getBean().info("HTTP_METHOD : " + request.getMethod());
//        LogUtil.getBean().info("IP : " + request.getRemoteAddr());
//        LogUtil.getBean().error("[系统异常]:", e);
//        LogUtil.getBean().error("-----end---------------------------------------------------------------------------------------");
//        return WebJsonResultUtil.error(e.getMessage());
//    }
//
//
//    public void log(LogTypeEnum logType, Exception exception) {
//        HttpServletRequest request = YzqpUtils.getServletRequest();
//        Log log = new Log();
//        log.setTitle(exception.getMessage());
//        log.setType(logType);
//        log.setRequestUri(request.getRequestURI());
//        log.setRequestMethod(request.getMethod());
//        log.setRemoteAddr(RequestUtil.getRemoteAddr(request));
//        log.setUserAgent(RequestUtil.getUserAgent(request));
//        Member member = YzqpUtils.getUserInfoCanNull();
//        if (member != null) {
//            log.setMemberId(member.getId());
//        }else {
//            log.setMemberId((long)2);
//        }
//        logService.newInsert(log);
//    }


}
